package com.geez.bbl.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * User: biniam.gebremichael
 * Date: Aug 23, 2010
 */
public class MatchUtils {
     public static String match(String candidate, String regex, Integer position) {
        Matcher matcher = Pattern.compile(regex).matcher(candidate);
        if (matcher.find()) {
            return matcher.group(position == null ? matcher.groupCount() : position);
        }
        return null;
    }

     public static Integer getCounter(String candidate) {
          String regex = "^(.*?)(\\d+)(.*?)$";
        Matcher matcher = Pattern.compile(regex).matcher(candidate);
        if (matcher.find()) {
            return Integer.valueOf(matcher.group(2));
        }
        return null;
    }
}
